Skip to content

fix: return 409 from set-workspace when multiple WSGI workers are in use#150

Merged
wpak-ai merged 3 commits into
masterfrom
fix/multiworker-set-workspace-honesty
Jul 22, 2026
Merged

fix: return 409 from set-workspace when multiple WSGI workers are in use#150
wpak-ai merged 3 commits into
masterfrom
fix/multiworker-set-workspace-honesty

Conversation

@clean6378-max-it

@clean6378-max-it clean6378-max-it commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Closes #144

With gunicorn running more than one worker, POST set-workspace only changed the in-memory override on the worker that handled the request.
The response still looked like success, so other workers kept the old path and operators had no signal that the change did not stick fleet-wide.

This branch blocks that case.
After path validation, the handler checks whether the deployment looks multi-worker using environment signals such as WEB_CONCURRENCY, GUNICORN_WORKERS, worker flags in GUNICORN_CMD_ARGS, or an explicit CURSOR_BROWSER_MULTI_WORKER override.
When that check is true, the API returns HTTP 409 with error code set_workspace_multi_worker_unsupported and tells the operator to set WORKSPACE_PATH or pass base-dir at startup instead of using the Configuration page. Single-process and single-worker behavior is unchanged when those signals are absent.

DEPLOYMENT.md now describes the 409 response and the env vars involved. tests/test_set_workspace_multiworker.py covers the 409 path, the success path when detection is off, and the env parsing helpers.
Sanity check by running that test module and the existing set-workspace API tests in test_workspace_path_validation.py.

Summary by CodeRabbit

  • Bug Fixes

    • Workspace updates now return a clear HTTP 409 when multiple worker processes are detected, and the workspace change is blocked.
    • Configuration page now shows an actionable error message (no redirect) when the workspace update fails, including the 409 case.
    • Single-process deployments still allow workspace changes.
  • Documentation

    • Updated production and multi-process deployment guidance, including worker settings and 409 behavior for POST /api/set-workspace.
  • Tests

    • Added/expanded tests covering multi-worker detection and the /api/set-workspace 409 vs 200 outcomes.

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 22 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9ab01a89-ff48-4d61-bd6a-07ab2cfa3984

📥 Commits

Reviewing files that changed from the base of the PR and between 6f30b91 and e4ca468.

📒 Files selected for processing (5)
  • DEPLOYMENT.md
  • api/config_api.py
  • templates/config.html
  • tests/test_set_workspace_multiworker.py
  • utils/workspace_path.py
📝 Walkthrough

Walkthrough

The workspace override endpoint now detects multi-worker deployments and returns HTTP 409 with a stable error code instead of applying a process-local override. The configuration UI handles this response, tests cover detection and endpoint behavior, and deployment documentation specifies startup configuration.

Changes

Multi-worker workspace safeguards

Layer / File(s) Summary
Multi-worker deployment detection
utils/workspace_path.py, tests/test_set_workspace_multiworker.py
Adds detection for explicit flags, worker-count environment variables, and Gunicorn worker arguments, with corresponding tests.
Workspace API rejection
api/config_api.py, tests/test_set_workspace_multiworker.py
Adds an early HTTP 409 response with code set_workspace_multi_worker_unsupported for multi-worker deployments while retaining single-process success.
Configuration UI and deployment guidance
templates/config.html, DEPLOYMENT.md
Centralizes workspace POST handling, displays failed-save messages, prevents redirects after failures, and documents WORKSPACE_PATH/--base-dir startup configuration.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Browser
  participant set_workspace
  participant WorkerDetection
  Browser->>set_workspace: POST /api/set-workspace
  set_workspace->>WorkerDetection: Check worker indicators
  WorkerDetection-->>set_workspace: Multi-worker status
  set_workspace-->>Browser: HTTP 409 error or HTTP 200 success
  Browser-->>Browser: Show error or continue redirect
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: returning 409 for multi-worker set-workspace requests.
Linked Issues check ✅ Passed The PR matches #144 by failing loudly under multi-worker deployments, preserving single-process behavior, and adding the requested test and docs updates.
Out of Scope Changes check ✅ Passed The added config-page 409 handling and worker-detection helper are directly related to the linked issue and not out of scope.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/multiworker-set-workspace-honesty

Comment @coderabbitai help to get the list of available commands.

@clean6378-max-it clean6378-max-it self-assigned this Jul 21, 2026
@clean6378-max-it

Copy link
Copy Markdown
Collaborator Author

@CodeRabbit, now can you start a revview about this pr? still limited to review?

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

@clean6378-max-it: Starting a review of this PR now. It will remain focused on the changes in this pull request.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@clean6378-max-it

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@bradjin8 bradjin8 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to have: handle 409 in config page

config.html calls /api/set-workspace without checking the response status. On 409, the UI may still show success. Consider surfacing body.error / body.code when res.status === 409.

Comment thread DEPLOYMENT.md
Comment thread tests/test_set_workspace_multiworker.py
@clean6378-max-it

Copy link
Copy Markdown
Collaborator Author

Nice to have: handle 409 in config page

config.html calls /api/set-workspace without checking the response status. On 409, the UI may still show success. Consider surfacing body.error / body.code when res.status === 409.

Config now checks the set-workspace response before we treat it as saved. On 409 we show the API error text and skip localStorage and the redirect.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@templates/config.html`:
- Around line 85-90: Update the auto-detect save flow after
postSetWorkspace(detected) so failed responses render saved.message through the
existing `#status-msg` error handling used by validateAndSave() before returning,
while preserving the current redirect behavior for successful saves.

In `@utils/workspace_path.py`:
- Around line 59-62: Update the worker-detection loop in the relevant
workspace-path helper so values greater than one return true, while
single-worker values continue checking later signals such as GUNICORN_WORKERS
and GUNICORN_CMD_ARGS. Add a regression test covering WEB_CONCURRENCY=1 together
with a later multi-worker signal and assert multi-worker mode is detected.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 97390ddc-a670-40ed-bcd7-20b08a46b97c

📥 Commits

Reviewing files that changed from the base of the PR and between 8e9ee40 and 4cf1d38.

📒 Files selected for processing (5)
  • DEPLOYMENT.md
  • api/config_api.py
  • templates/config.html
  • tests/test_set_workspace_multiworker.py
  • utils/workspace_path.py

Comment thread templates/config.html
Comment thread utils/workspace_path.py Outdated
@clean6378-max-it
clean6378-max-it force-pushed the fix/multiworker-set-workspace-honesty branch from 6f30b91 to e4ca468 Compare July 21, 2026 21:47
@bradjin8
bradjin8 requested a review from wpak-ai July 22, 2026 01:49
@wpak-ai
wpak-ai merged commit 02936aa into master Jul 22, 2026
17 checks passed
@wpak-ai
wpak-ai deleted the fix/multiworker-set-workspace-honesty branch July 22, 2026 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cppa-cursor-browser: make multi-worker set-workspace propagate or fail loudly

3 participants